export const getTodayDate = () => {
  const today = new Date();
  return today.toISOString().split('T')[0];
}

export const getSpecialDayBaseToday = (day: number) => {
  const today = new Date();
  today.setDate(today.getDate() + day);
  return today.toISOString().split('T')[0];
}

export const getSpecialDayBeforeDate = (target: Date, days: number) => {
  const date = new Date(target);
  date.setDate(date.getDate() - days);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
}

export const getDatesInRange = (targetDate: string, range: number) => {
  const dates: string[] = [];
  const target = new Date(targetDate);
  for (let i = 0; i < range; i++) {
    dates.push(getSpecialDayBeforeDate(target, i + 1));
  }
  return dates;
}

export const getDayOfWeek = (textType: 'zhou' | 'xingqi', dateTime?: string): string => {
  const days = {
    'zhou': ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
    'xingqi': ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  };

  const date = new Date(dateTime || getTodayDate());
  const dayIndex = date.getDay(); // 获取今天是星期几，0 表示星期日，1 表示星期一，以此类推
  return days[textType][dayIndex];
}
